import { Camera3D, Scene3D, WebGLRenderer3D } from 'feng3d-three';
import { AsciiEffect, AsciiEffectOptions } from '../thirdparty/three/imports';

export class AsciiEffect3D
{
    _asciiEffect: AsciiEffect;

    get domElement()
    {
        return this._asciiEffect.domElement;
    }
    set domElement(v)
    {
        this._asciiEffect.domElement = v;
    }

    constructor(renderer: WebGLRenderer3D, charSet?: string, options?: AsciiEffectOptions)
    {
        this._asciiEffect = new AsciiEffect(renderer._webGLRenderer, charSet, options);
    }

    setSize(width: number, height: number)
    {
        this._asciiEffect.setSize(width, height);
    }

    render(scene: Scene3D, camera: Camera3D)
    {
        // 修复渲染前更新摄像机矩阵数据
        // @see https://github.com/mrdoob/three.js/blob/r149/src/renderers/WebGLRenderer.js#L963
        camera.updateMatrixWorld();
        //
        this._asciiEffect.render(scene._scene, camera._camera);
    }
}
